#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> 
// https://leetcode.cn/problems/find-pivot-index/description/
int pivotIndex(int* nums, int numsSize) {
    int total = 0;
    for (int i = 0; i < numsSize; i++) {
        total += nums[i];
    }
    int leftSum = 0;
    for (int i = 0; i < numsSize; i++) {
        int rightSum = total - leftSum - nums[i];
        if (leftSum == rightSum) {
            return i;
        }
        leftSum += nums[i];
    }
    return -1;
}
int main() {
    int nums[] = { 1,7,3,6,5,6 };
    printf("%d\n", pivotIndex(nums, sizeof(nums) / sizeof(nums[0])));
    return 0;
}